const web = require("../../module/web"), loger = require("../../module/loger");

module.exports.run = ()=>{
	web.run((w)=>{
		if(!w.window.$){
			web.reload();
			return;
		}
		let lt = w.window.document.getElementById("tabsUl");
		if(lt){
			lt = lt.getElementsByTagName("a");
			for(let i=0;i<lt.length;i++){
				if(lt[i].innerHTML.indexOf("手机号码邮箱") > 0){
					lt[i].click();
					break;
				}
			}
		} 
		
		let inp = w.window.document.getElementById("mobileIpt");
		if(inp) inp.value = global.sdObj.ud[3];
		w.window.$("#mobileIpt").blur();
		inp = w.window.document.getElementById("mobilePwdIpt");
		if(inp) inp.value = global.sdObj.ud[10];
		w.window.$("#mobilePwdIpt").blur();
		inp = w.window.document.getElementById("mobileCfmPwdIpt");
		if(inp) inp.value = global.sdObj.ud[10];
		w.window.$("#mobileCfmPwdIpt").blur();
		
	},(w)=>{
		if(!w.window.$){
			web.reload();
			return;
		}
		let lt = w.window.document.getElementById("tabsUl");
		if(lt){
			lt = lt.getElementsByTagName("a");
			for(let i=0;i<lt.length;i++){
				if(lt[i].innerHTML.indexOf("手机号码邮箱") > 0){
					lt[i].click();
					break;
				}
			}
		} 
		
		let inp = w.window.document.getElementById("mobileIpt");
		if(inp) inp.value = global.sdObj.ud[3];
		w.window.$("#mobileIpt").blur();
		inp = w.window.document.getElementById("mobilePwdIpt");
		if(inp) inp.value = global.sdObj.ud[10];
		w.window.$("#mobilePwdIpt").blur();
		inp = w.window.document.getElementById("mobileCfmPwdIpt");
		if(inp) inp.value = global.sdObj.ud[10];
		w.window.$("#mobileCfmPwdIpt").blur();
		
		inp = w.window.document.getElementById("m_mobile");
		if(inp && inp.innerHTML.indexOf("该号码可注册") == -1){
			global.sdObj.end = 1;
			return true;
		}
		
		//获取短信验证码
		inp = w.window.document.getElementById("sendAcodeBtn");
		if(inp) inp.click();
		if(inp && inp.innerHTML.indexOf("重新获取验证码") != -1){
			if(global.sdObj.cmds.length > 0) global.sdObj.finish = 1;
			else global.sdObj.end = 0;
			return true;			
		}
	});
}